/* START 0_prepFarecardData.do */

/* this script prepares the .dta files associated with farecard data
.txt from 2015-2016, as well as the panel. */

set more off

do code/config.do

local panel_flag 1 /* distinguish between panel and 2015 data. Toggle to `0` to export 2015 data. */

if `panel_flag' == 1 {
	local fileList 1_7Dec2016 1_7Dec2017 1_7Jun2015 1_7Jun2016 ///
	  1_7Jun2017 1_7Jun2018 1_7Mar2016 1_7Mar2017 ///
	  1_7Mar2018 1_7Sep2015 1_7Sep2016 1_7Sep2017
	}
else {
	local fileList 1dec2015_10dec2015 11dec2015_20dec2015 ///
	  11feb2016_20feb2016 11jan2016_20jan2016 1feb2016_10feb2016 ///
	  1jan2016_10jan2016 21dec2015_31dec2015 21feb2016_1mar2016 ///
	  21jan2016_31jan2016
	}

// clean and save data frames in each successive text file
foreach rawFile in `fileList' {
	cap clear
	disp "now processing data from `rawFile'"
   import delimited "../data/`rawFile'.txt", case(upper) colrange(2)
   drop BIZ_DT
   
   // strip numeric variables of "?"
   foreach x of varlist JRNY_ORIG_ID_NUM JRNY_DEST_ID_NUM {
   	destring `x', ignore("?") replace
   	}

	cap destring PATRON_CATG_ID_NUM, ignore ("?") replace
	cap destring JRNY_DIST_KM_CNT, ignore ("?") replace
   
   foreach x of varlist JRNY_START_TM JRNY_END_TM {
   	replace `x' = substr(`x', 1, 8)
   	}
   
   foreach x in START END {
   	gen double `x' = clock(JRNY_`x'_DT + " " + JRNY_`x'_TM, "DMY hms")
   	}
   format %tc START END
	format CRD_NUM %18.0g
   drop JRNY_START_DT JRNY_START_TM JRNY_END_DT JRNY_END_TM

	save "../make_data/`rawFile'.dta", replace
   
	}

// minimum discernable travel time is 2 minutes
